package com.ims.common.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;



import com.ims.stocks.model.UserDetails;
import com.opensymphony.xwork2.ActionContext;

public class BaseModel implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8897372331594234807L;

	private Integer createdBy;
	private Date createdOn;
	private Integer lastUpdatedBy;
	private Date lastUpdatedOn;
	
	
	public Integer getCreatedBy() {
		return createdBy;
	}
	public void setCreatedBy(Integer createdBy) {
		this.createdBy = createdBy;
	}
	public Date getCreatedOn() {
		return createdOn;
	}
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}
	public Integer getLastUpdatedBy() {
		return lastUpdatedBy;
	}
	public void setLastUpdatedBy(Integer lastUpdatedBy) {
		this.lastUpdatedBy = lastUpdatedBy;
	}
	public Date getLastUpdatedOn() {
		return lastUpdatedOn;
	}
	public void setLastUpdatedOn(Date lastUpdatedOn) {
		this.lastUpdatedOn = lastUpdatedOn;
	}
	
	public void setAuditColumns(){
		Map session = ActionContext.getContext().getSession();
		UserDetails userinfo = (UserDetails)session.get("userinfo");
		Date today = new Date();
		Integer id = userinfo.getUserDetailsId();
		if(this.getCreatedBy()==null){
			this.setCreatedBy(id);
			this.setCreatedOn(today);		
		}
		this.setLastUpdatedBy(id);
		this.setLastUpdatedOn(today);
	}
	
}
